package com.f5.management.dao;

import com.f5.management.entity.Building;
import com.f5.management.entity.Community;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Mapper
@Repository
public interface BuildingDAO {

    //分页查询
    List<Building> findAll();

    //条件查询信息
    List<Building> findByCid(@Param("cid") int cid, @Param("name") String name, @Param("serialNumber") String serialNumber);

    //删除信息
    @Delete("delete from building_management where id = #{id}")
    int delInfo(int id);

    //添加
    @Insert("insert into building_management(id,cid,serialNumber,name,peopleNumber,represent,createTime) " +
            "values(default,#{cid},#{serialNumber},#{name},#{peopleNumber},#{represent},#{createTime})")
    int add(Building building);

    //查询存在的栋数及编号
    @Select("select count(id) from building_management")
    int count();

    //通过名字查询id
    @Select("select id from building_management where name = #{name}")
    int findBidByName(String name);

    //更改信息
    @Update("update building_management set serialNumber=#{serialNumber},name=#{name}," +
            "peopleNumber=#{peopleNumber},represent=#{represent} where id = #{id}")
    int updateInfo(Building building);

    //更改状态
    @Update("update building_management set status=#{status} where id = #{id}")
    int updateStatus(@Param("id") int id, @Param("status") boolean status);

    //id查询数据进行修改
    @Select("select * from building_management where id = #{id}")
    Building findById(int id);

    //查询编号是否存在
    @Select("select serialNumber from building_management where serialNumber = #{serialNumber}")
    String selectNumber(String serialNumber);

    //查询名字是否存在
    @Select("select name from building_management where name = #{name}")
    String selectName(String name);
}
